package com.dingding.common.core.base.dto;

import java.io.Serializable;

import org.apache.http.HttpStatus;

/**
 * @Description:封装接口的返回
 * @author fengshuonan
 * @date 2016年9月20日 下午5:26:02
 * @version 叮叮搭车
 * @since 2.4
 */
@SuppressWarnings("serial")
public class FacadeResult<T> implements Serializable{

	private Integer code = HttpStatus.SC_OK;	//状态码  默认为200 成功 
		
	private String message = "请求成功";			//提示信息
		
	private T object;							//响应bean
	
	public FacadeResult() {
		super();
	}

	public FacadeResult(T object) {
		super();
		this.object = object;
	}

	public FacadeResult(Integer code, String message) {
		super();
		this.code = code;
		this.message = message;
	}

	public FacadeResult(Integer code, String message, T object) {
		super();
		this.code = code;
		this.message = message;
		this.object = object;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getObject() {
		return object;
	}

	public void setObject(T object) {
		this.object = object;
	}
	
	public static <T> FacadeResult<T> SUCCESS(T t){
		FacadeResult<T> facadeResult = new FacadeResult<>();
		facadeResult.setCode(HttpStatus.SC_OK);
		facadeResult.setMessage("请求成功");
		facadeResult.setObject(t);
		return facadeResult;
	}
	
	public static <T> FacadeResult<T> SUCCESS(){
		FacadeResult<T> facadeResult = new FacadeResult<>();
		facadeResult.setCode(HttpStatus.SC_OK);
		facadeResult.setMessage("请求成功");
		return facadeResult;
	}
	
	public static <T> FacadeResult<T> ERROR(int code,String message){
		FacadeResult<T> facadeResult = new FacadeResult<>();
		facadeResult.setCode(code);
		facadeResult.setMessage(message);
		return facadeResult;
	}
	
	public static <T> FacadeResult<T> ERROR(){
		FacadeResult<T> facadeResult = new FacadeResult<>();
		facadeResult.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
		facadeResult.setMessage("服务器未知异常");
		return facadeResult;
	}
	
	@Override
	public String toString() {
		return "FacadeResult [code=" + code + ", message=" + message + ", object=" + object + "]";
	}
	
	
}
